<template>
  <iframe id="iframe1" :key="ikey" ref="Iframe" :src="url" frameborder="0" />
</template>

<script lang="ts">
  import { getAppEnvConfig } from '/@/utils/env';
  import { getUserOrganization } from '/@/api/ehs/organization';
  import { onMounted, ref, watchEffect, defineComponent, ref } from 'vue';
  import { useGlobSetting } from '/@/hooks/setting';
  const { globalProjectCode, apiUrl } = useGlobSetting();
  export default defineComponent({
    name: 'EduRecordIndex',
    components: {},
    setup() {
      const projectCode = ref<String>(globalProjectCode);
      const ikey = new Date().getTime(); // 使用时间戳
      const Iframe = ref();
      const loading = ref(false);
      const orgcode = ref('');
      const orgname = ref('');

      function iframeLoad() {
        window.parent.postMessage(orgcode.value, '*');
      }
      const url = ref();
      const fetchData = () => {
        if (!url.value) {
          // ikey.value = new Date().getTime() // 使用时间戳
          url.value =
            'http://192.168.197.211:8080/dev/ehs/datav/#/dashboardA-cn/' +
            orgcode.value +
            '/' +
            orgname.value;
          // url.value =
          //   '118.195.173.130/ehs/datav/#/dashboardA-cn/' + orgcode.value + '/' + orgname.value;
        }
        // iframeLoad();
      };

      onMounted(() => {
        getUserOrganization(projectCode.value).then((res) => {
          orgcode.value = res.orgcode ?? '';
          orgname.value = res.orgname ?? '';
          fetchData();
        });
      });

      return {
        ikey,
        url,
      };
    },
  });
</script>

<style scoped>
  #iframe1 {
    width: calc(100vw - 200px);
    height: calc(100vh - 80px);
  }
</style>
